package com.lijie.ljblog.chess;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description
 * @Author lijie
 * @Date 2022/10/25 14:52
 **/
@Component
public class OnlineUserManager {
    //
    private ConcurrentHashMap<Integer, WebSocketSession> game_hall = new ConcurrentHashMap<>();
    private ConcurrentHashMap<Integer, WebSocketSession> game_room = new ConcurrentHashMap<>();

    /**
     * 用户进入游戏大厅
     */
    public void enterGameHall(int userId,WebSocketSession session){
        game_hall.put(userId,session);
    }

    /**
     *    用户离开游戏大厅
     * @param userId
     */
    public void exitGameHall(int userId){
        game_hall.remove(userId);
    }

    /**
     * 获取用户信息
     * @param userId
     * @return
     */
    public WebSocketSession getGameHallSession(int userId){
        return game_hall.get(userId);
    }

    /**
     * 用户进入游戏房间
     * @param userId
     * @param session
     */
    public void enterGameRoom(int userId,WebSocketSession session){
        game_room.put(userId,session);
    }

    //用户离开游戏房间
    public void exitGameRoom(int userId){
        game_room.remove(userId);
    }

    //获取用户信息
    public WebSocketSession getGameRoomSession(int userId){
        return game_room.get(userId);
    }


}
